import axios from "axios";
import Vue from "vue";

// 创建axios实例
const service = axios.create({
    baseURL:'/api',
    timeout:15000 //请求超时时间
})

// request请求拦截器
service.interceptors.request.use(
    request => {
        return request
    },
    error => {
        console.log("错误发生了："+error)
        return Promise.reject(error)
    }
)

// response 响应拦截器
service.interceptors.response.use(
    response => {
        switch (response.data.code) {
            case 50000:
                Vue.prototype.$toast({type:"error",message:"系统错误"})
        }
        return response
    },
    error => {
        return Promise.reject(error)
    }
)

export default service
